// function getFoo () {
//   return new Promise(function (resolve, reject){
//     resolve('foo');
//   });
// }

// const g = function* () {
//   try {
//     const foo = yield getFoo();
//     console.log(foo);
//   } catch (e) {
//     console.log(e);
//   }
// };

// function run (generator) {
//   const it = generator();

//   function go(result) {
//     if (result.done) return result.value;

//     return result.value.then(function (value) {
//       return go(it.next(value));
//     }, function (error) {
//       return go(it.throw(error));
//     });
//   }

//   go(it.next());
// }

// run(g);


// function showLoading() {
//   console.log(true);
// }

// function hideLoading() {
//   setTimeout(() => {
//     console.log(false);
//   });
// }

// function getValue() {
//   return new Promise((resolve) => {
//     showLoading();
//     resolve(1);
//   });
// }

// getValue().then(() => {
//   hideLoading();
//   return getValue();
// }).then(() => {
//   hideLoading();
//   return getValue();
// });

// console.log('test');

fetchRulesFromBid = (treeData, promises=[]) => {
  treeData.forEach(item => {
    if (item.children && item.children.length) {
      fetchRulesFromBid(item, promises);
    }
  });
}


fetchRules = (treeData) => {
    treeData.forEach((item) => {
        if (item.children && item.children.length > 0) {
            this.fetchRules(item.children)
        } else {
            //根据评价体系叶子节点查询评价指标listRulesBySysId
            listRulesBySysId({"systemId": item.id}).then((res) => {
                return {
                    weightConfig: {label: item.name, id: item.id},
                    systemMapRuleData: {[item.id]: this.mapOldFieldNameToNew(res)}
                }
            });
        }
    })
}

getRules = (treeData) => {
    let promises = [];
    this.fetchRules(treeData,promises);
    return Promise.all(promises).then((res)=>{
        console.log("getRules",res)
        let weightConfig = [],systemMapRuleData = {};
        res.map((item)=>{
            weightConfig.push(item.weightConfig);
            systemMapRuleData = {...systemMapRuleData,...item.systemMapRuleData}
        });
        console.log("weightConfig",weightConfig)
        console.log("systemMapRuleData",systemMapRuleData)
        this.setState({weightConfig, systemMapRuleData});
    });
}

mapOldFieldNameToNew = (data) => {
    return data.map((item) => ({
        parentId: item.parent && item.parent.id,
        rank: rankId++,
        indicatorName: item.child && item.child.name,
        indicatorDefine: item.child && item.child.definition,
        evaluationStandard: item.markStandard,
        multipleRule: item.mutiScoreStandard,
        highestScore: item.highestScore
    }));
}





